<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>添加首页广告</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0"><!-- 确保适当的绘制和触屏缩放 -->
	<link rel="stylesheet" href="{$url_css}bootstrap.min.css" type="text/css">
	<link rel="stylesheet" href="{$url_css}admin.css" type="text/css">
	<link rel="stylesheet" href="{$url_js}fileinput/css/fileinput.min.css" type="text/css">
	<link rel="stylesheet" href="{$url_css}tagcate.css" type="text/css">
	<link rel="stylesheet" href="{$url_css}viewer.min.css" type="text/css"/>


	<script type="text/javascript" src="{$url_js}calendar/WdatePicker.js"></script>
	<script type="text/javascript" src="{$url_js}jquery-2.2.0.min.js"></script>
	<script type="text/javascript" src="{$url_js}bootstrap.min.js"></script>
	<script type="text/javascript" src="{$url_public}editor/ckeditor/ckeditor.js"></script>
	<script type="text/javascript" src="{$url_public}editor/ckfinder/ckfinder.js"></script>
	<script type="text/javascript" src="{$url_js}fileinput/js/fileinput.min.js"></script>
	<script type="text/javascript" src="{$url_js}fileinput/js/locales/zh.js"></script>
	<script type="text/javascript" src="{$url_js}fileinput/js/plugins/canvas-to-blob.min.js"></script>
	<script type="text/javascript" src="{$url_js}tagcate.js"></script>
	<script type="text/javascript" src="{$url_js}viewer-jquery.min.js"></script>
	<script type="text/javascript" src="{$url_js}layer/layer.js"></script>

	<style type="text/css">
		{literal}
		.file-drop-zone {
			min-height: 198px;
		}

		.file-thumbnail-footer {
			display: none;
		}

		.audio .file-preview-frame {
			height: 28px !important;
		}

		.audio .file-drop-zone {
			min-height: 92px;
		}

		.div_btn {
			width: 100%;
		}

		.div_btn input {
			width: 7%;
		}

		{/literal}
	</style>
</head>
<body>

<div class="container" style="width:96%">
	<form action="?do=Updata" method="post" enctype="multipart/form-data">
		<input type="hidden" name="id" value="{$info.Id}">
		<table class="table table-bordered table-striped" align="center">
			<tbody>
			<tr>
				<td colspan="3"><h5>添加首页广告</h5>
				</td>
			</tr>

			<tr>
				<td>标题：</td>
				<td><input type="text" class="form-control" id="title" name="title" value="{$info.Title}"
				           placeholder="标题" style="width: 500px;" maxlength="10"/></td>
			</tr>
			<tr>
				<td>文案：</td>
				<td><textarea class="form-control" id="keywords" name="description" style="width: 400px;height: 120px"
				              placeholder="文案......">{$info.Description}</textarea></td>
			</tr>

			<tr>
				<td>
					上传icon图片(仅限jpg&png格式)
				</td>
				<td>
					<input type="file" id="icon" name="icon" class="file_img"
					       data="{if $info}{$info['IconUrl']}{/if}"/>
				</td>
			</tr>
			{*<tr>*}
				{*<td>点击跳转URL：</td>*}
				{*<td><input type="text" class="form-control" id="url" name="url" value="{$info.Url}"*}
				           {*placeholder="点击跳转URL" style="width: 500px;"/></td>*}
			{*</tr>*}

			<tr>
				<td>
					上传图片一(仅限jpg&png格式，<br>图片大小为156*156)
				</td>
				<td>
					<input type="file" id="img" name="img" class="file_img"  minW="156" minH="156"
					       data="{if $info}{$info['ImgUrl']}{/if}"/>
				</td>
			</tr>
			<tr>
				<td>图一URL选择</td>
				<td>
					<div style="width:160px;height:35px;float:left;">
						<select class="form-control" style="width: 150px;" onchange="selecturl(this.value)">
							<option value="">请选择</option>
							{foreach $scheme['appScheme'] as $k => $v}
								<option value="{$k}" {if $info.ClickUrl === $k}selected{/if}>{$v}</option>
							{/foreach}
						</select>
					</div>
					<div style="width:160px;height:35px;float:left;">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a onclick="SelectItem(1)" class="btn btn-info">添加商品URL</a>
					</div>
				</td>
			</tr>
			<tr>
				<td>图片一点击跳转URL：</td>
				<td><input type="text" class="form-control" id="imgurl" name="imgurl" value="{$info.ClickUrl}"
				           placeholder="图片一点击跳转URL" style="width: 500px;" /></td>
			</tr>

			<tr>
				<td>
					上传图片二(仅限jpg&png格式，<br>图片大小为156*156)
				</td>
				<td>
						<input type="file" id="img2" name="img2" class="file_img" minW="156" minH="156"
						       data="{if $info}{$info['ImgUrl2']}{/if}"/>
				</td>
			</tr>
			<tr>
				<td>图二URL选择</td>
				<td>
					<div style="width:160px;height:35px;float:left;">
						<select class="form-control" style="width: 150px;" onchange="selecturl2(this.value)">
							<option value="">请选择</option>
							{foreach $scheme['appScheme'] as $k => $v}
								<option value="{$k}" {if $info.ClickUrl2 === $k}selected{/if}>{$v}</option>
							{/foreach}
						</select>
					</div>
					<div style="width:160px;height:35px;float:left;">
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<a onclick="SelectItem(2)" class="btn btn-info">添加商品URL</a>
					</div>
				</td>
			</tr>

			<tr>
				<td>图片二点击跳转URL：</td>
				<td><input type="text" class="form-control" id="imgurl2" name="imgurl2" value="{$info.ClickUrl2}"
				           placeholder="图片二点击跳转URL" style="width: 500px;" /></td>
			</tr>

			<tr>
				<td>
					<div>首页广告开始时间</div>
				</td>
				<td>
					<div class="input-group">
						<input class="form-control" id="start_time" name="start_time" type="text"
						       onFocus="WdatePicker({literal}{startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'end_time\')}'}{/literal});"
						       value="{$info['StartTime']}" readonly="">
					</div>
				</td>
			</tr>
			<tr>
				<td>
					<div>首页广告结束时间</div>
				</td>
				<td>
					<div class="input-group">
						<input class="form-control" id="end_time" name="end_time" type="text"
						       onFocus="WdatePicker({literal}{startDate:'%y-%M-%d 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'start_time\')}'}{/literal});"
						       value="{$info.EndTime}" readonly="">
					</div>
				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td align="center">
					<input type="submit" id="add_btn" class="btn btn-primary" value="保存"/>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="button" onclick="history.back()" class="btn btn-primary" value="取消"/>
				</td>
			</tr>
			</tbody>
		</table>
	</form>
</div>
<div>&nbsp;</div>

{literal}
	<script>
		function SelectItem(urltype){
            layer.open({
                type: 2,
                title: '商品URL挑选',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area : ['80%' , '60%'],
                content: '/data/modules/share/Ecommerce.php?do=SelectItemsType&urltype='+urltype
            });
        }

        function selecturl(url){
            var imgurl = $("#imgurl");
            imgurl.removeAttr("value");
            imgurl.val(url);
        }

        function selecturl2(url){
            var imgurl2 = $("#imgurl2");
            imgurl2.removeAttr("value");
            imgurl2.val(url);
        }

        $("#add_btn").click(function () {
            var title = $.trim($("#title").val()),
//                url = $.trim($("#url").val()),
                icon = $.trim($('#icon').val()),
                imgurl = $.trim($("#imgurl").val()),
                img = $.trim($('#img').val()),
                start_time = $.trim($('#start_time').val()),
                end_time = $.trim($('#end_time').val());

            if (!title.length) {
                top.swal('出错了', '标题不能为空！', 'error');
                return false;
            }

            var data = $("#icon").attr("data");
            if (data == '') {
                if (!/\.(jpg|png)$/.test(icon)) {
                    top.swal('出错了', '未选择icon图片, 且图片必须为jpg或png格式', 'error');
                    return false;
                }
            }

//            if (!url.length) {
//                top.swal('出错了', '链接不能为空！', 'error');
//                return false;
//            }

            var data = $("#img").attr("data");
            if (data == '') {
                if (!/\.(jpg|png)$/.test(img)) {
                    top.swal('出错了', '未选择图片一, 且图片必须为jpg或png格式', 'error');
                    return false;
                }
            }

            if (!imgurl.length) {
                top.swal('出错了', '图一链接不能为空！', 'error');
                return false;
            }

            if (!start_time.length) {
                top.swal('出错了', '广告开始时间不能为空！', 'error');
                return false;
            }

            if (!end_time.length) {
                top.swal('出错了', '广告结束时间不能为空！', 'error');
                return false;
            }

            return true;
        });

        //图片上传初始化
        $(".file_img").each(function () {
            var accept = ['jpg', 'png', 'gif'];
            var input_obj = $.extend(uploadObj(), {
                allowedPreviewTypes: ['image'],
                allowedFileTypes: ['image'],
                allowedFileExtensions: accept,//接收的文件后缀
                resizeImage: true
            });

            $(this).attr("accept", '.' + accept.join(',.'));
            var img_url = $(this).attr("data");
            if (img_url != '') {
                input_obj.initialPreview = [
                    '<img src="' + img_url + '" class="kv-preview-data file-preview-image" style="width:auto;height:160px;">'
                ];
            }

            var maxSize = $(this).attr("maxSize");
            if (maxSize > 0) {
                input_obj.maxFileSize = maxSize;
            }

            var minW = $(this).attr("minW");
            if (minW > 0) {
                input_obj.minImageWidth = minW;
            }

            var minH = $(this).attr("minH");
            if (minH > 0) {
                input_obj.minImageHeight = minH;
            }


            $(this).fileinput(input_obj)
        });

        //上传插件对象
        function uploadObj() {
            return obj = {
                showCaption: false,
                showClose: false,
                uploadAsync: false,
                showRemove: false,
                showUpload: false,
                uploadUrl: "#",
                language: 'zh', //设置语言
                dropZoneEnabled: false,
            };
        }
	</script>
{/literal}

</body>
<html>